<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="../../../attr.jsp"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="${ctx}/css/sapar.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/common.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/css/kkpager_blue.css" />
<script type="text/javascript" src="${ctx}/js/jquery.js"></script>
<script type="text/javascript" src="${ctx}/js/sapar.js"></script>
<script type="text/javascript" src="${ctx}/js/WdatePicker.js"></script>
<script type="text/javascript" src="${ctx}/assets/layer/layer.js"></script>
<script type="text/javascript" src="${ctx}/js/kkpager.min.js"></script>
<script type="text/javascript" src="${ctx}/assets/laydate/laydate.js"></script>
<script type="text/javascript" src="${ctx}/js/mask.js"></script>
<title>生物监测审核</title>
<style  type="text/css">
th{
text-align: center;
}
td{
text-align: center;
}
#left{
	float:left; width:100%;
}
#saper-container{float:left;width:100%;background: url(../images/dian.png) repeat-y 69% 0;}
#table_left{float:left; width:68%;min-height:300px}
#right{
	float:right; width:30%;min-height:200px
}
#ren{
	float: left;
	margin-left: 20px;
	margin-top: 5px;
	margin-bottom: -15px;
}
</style>
</head>

<body>
<div id="mask" class="mask"></div>
<div id="left">
	<div id="saper-container">
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>生物监测审核</h2>
            </div>
            
            <div class="subfiled-content">

                <!--表格开始-->
                <form onkeydown="if(event.keyCode==13)return false;" id="miejunShenhe">
                <%--<div class="kv-item clearfix" id="ren">--%>
	              	<%--<span>审核人  :</span>--%>
	               	<%--<input type="text"  name="miejunShenherenTiaoma" placeholder="审核人" id="shr" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">--%>
					<%--<a href="javascript:;" class="sapar-btn sapar-btn-recom" id="baocun" >保存</a>--%>
                <%--</div>--%>
					<div class="kv-item clearfix" >
						<div id="ren">
							<span>审核人  :</span>
							<input type="text"  name="miejunShenherenTiaoma" placeholder="审核人" id="shr" onkeyup="this.value=this.value.replace(/(^\s*)|(\s*$)/g,'')">
						</div>
						<div >
							<a href="javascript:;" class="sapar-btn sapar-btn-recom" id="baocun" >保存</a>
						</div>
					</div>



                <div id="table_left" class="table">
                    <!--表格操作-->
                    
                    <!--表格具体内容-->
                    
                    <div class="table-box">
                        <table>
                            <thead>
                                <tr>
                                    <%--<th>灭菌流水</th>--%>
                                    <th>灭菌机器</th>
                                    <th>灭菌软件</th>
                                    <th>灭菌人名称</th>
                                    <th>灭菌开始时间</th>
                                    <th>灭菌结束时间</th>
                                    <th>审核</th>
                                </tr>
                            </thead>
                            <tbody>
                                <c:if test="${lstMiejun != null}">
									<!-- var 是给给他起名字 -->
									<c:forEach items="${lstMiejun}" var="miejun">
										<tr data="${miejun.miejunLiushui}" class="miejunData">
											<%--<td>${miejun.miejunLiushui }</td>--%>
											<td></td>
											<td><input type="hidden" name="miejunLiushui" value="${miejun.miejunLiushui }">${miejun.zsEquip.equipName}</td>
											<td>${miejun.zsSoft.softName}</td>
											<td>${miejun.miejunren.employeeName}</td>
											<td><fmt:formatDate value="${miejun.miejunKaishiTime}"
													type="date" pattern="MM-dd HH:mm" /></td>
											<td><fmt:formatDate value="${miejun.miejunJieshuTime}"
													type="date" pattern="MM-dd HH:mm" /></td>
											<td>
												 <select name="miejunHege">
													<option value="2">合格</option>
													<option value="1">不合格</option>
												 </select>
											 </td>
												
										</tr>
									</c:forEach>
								</c:if>
                                 
                            </tbody>
                            
                        </table>
                    <%--<div id="saper-ft">--%>
        	        <%--<div id="kkpager"></div>--%>
                    <%--</div>--%>
                        
                    </div>
                </div><!--表格结束-->
                </form>
                
	            <div id="right">
				    <div class="table">
						<div class="table-box">
	                        <table id="detail">
	                            <thead>
	                                <tr>
	                                    <th>灭菌包条码</th>
	                                    <th>灭菌包名称</th>
	                                    <th>是否合格</th>
	                                </tr>
	                            </thead>
	                            <tbody>
	                                
	                            </tbody>
	                        </table>
	                    </div>
	                    <div>
						<input id="leftPage" class="butLeft" type="button" value="上一页" />
						<input id="rightPage" class="butRight" type="button" value="下一页" />
						<span>到第&nbsp;</span><input id="goPage" class="textBox" type="text" value="1" /><span style="margin-left: 4px;">页&nbsp;</span>
						<input  id="sureBut" class="sure" type="button" value="确定" />
					 	<span>共</span><span class="totalPages" id="totalNum">0</span><span>&nbsp;页</span>
					    </div>
                    </div>
				</div>
			</div>
        </div>
        <div id="saper-ft">
        	<div id="kkpager"></div>
        </div>
    </div>
   </div> 
<script type="text/javascript">
window.onload = function(){
	$("#shr").focus();
}
var pageSize = 10 , currentPage = 1 , totalPage;
var data = [];

function isNullOrEmpty(strVal){
	strVal = strVal.replace(/(^\s*)|(\s*$)/g,"");
	if(strVal == '' || strVal == null || strVal == undefined){
		return true;
	}else{
		return false;
	}
}

$(document).keydown(function (event) {
    var oPlay0 = document.getElementById("audio");
    var oPlay1 = document.getElementById("audio1");
    var packageName = $("input[name='packageName']").val();
    if (event.keyCode == 13) {
        if ($("#shr").is(":focus") ) {
            $("#baocun").click();
        }
    }
});

function getParameter(name) { 
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); 
	var r = window.location.search.substr(1).match(reg); 
	if (r!=null) return unescape(r[2]); 
	return null;
}

	$(function(){
		var totalPage = ${total};
    	var pageNo = getParameter('pageIndex');
    	if(!pageNo){
    		pageNo = 1;
    	}
    	kkpager.generPageHtml({
    		pno : pageNo,
    		//总页码
    		total : totalPage,
    		//链接前部
    		hrefFormer : '${ctx}/miejun/miejunTwo',
    		//链接尾部
    		hrefLatter : '.do',
    		getLink : function(n){
    			return this.hrefFormer + this.hrefLatter + "?pageIndex="+n+"&searchTxt="+$(".search_text").val();
    		}
    	});
		
		$("#baocun").click(function(){
			var btn = true;
			var txt = $("#shr").val();
			if(isNullOrEmpty(txt)){
				btn = false;
				alert("请输入审核人");
				return false;
			}
			if(btn){
				showMask();
				$.ajax({
					type:"post",
					url:"${ctx}/miejun/updateShenheAndHegeTwo.do",
					error:function(){
						layer.alert("网络故障，稍后再试");
					},
					data:$("#miejunShenhe").serialize(),
					success:function(data){
						$("#mask").hide();
						if(data.state=="true"){
							 layer.alert(data.msg,function(){
								 window.location.reload(); 
							 });
		 	           	}else{
		 	           		 layer.alert(data.msg);
		 	           	}
					}
				});
			}
		});		
		
		$(".miejunData").click(function(){
			$(this).addClass("xuanzhong").siblings().removeClass("xuanzhong");
			var liushuiId = $(this).attr("data");
			$.ajax({
				type:"post",
				url:"${ctx}/miejun/findByMiejunLiushui.do?id="+liushuiId,
				error:function(){
					layer.alert("网络故障，稍后再试");
				},
				success:function(data){
					if(data.state=="true"){
		 	           	 /* console.log(data);
		 	           	 var dataList = data.lstMiejunmingxi;
		 	           	 var str = '';
		 	           	 $("#detail tbody").empty();
		 	           	 for(var i = 0; i<dataList.length;i++){
		 	            	str += "<tr><td>"+dataList[i].miejunWupinbaoTiaoma+"</td><td>"+dataList[i].zsPackageImformation.packageName+"</td><td>"+(dataList[i].miejunHege==3?"合格":"二审")+"</td></tr>";
		 	           	 }
		 	           	 $("#detail tbody").append(str); */
						appendTable(data);
	 	           	}else{
	 	           		 layer.msg(data.msg);
	 	           	}
				}
			});
		});
		
		$("#sureBut").click(function(){
			goPage();
		});
		$("#leftPage").click(function(){
			leftPages();
		});
		$("#rightPage").click(function(){
			rightPages();
		});
    });
	
	//=================================================================	

	function appendTable(dataList){
		 currentPage = 1  ;
         data = dataList.lstMiejunmingxi;
         packageId = dataList.packageId;
         creatTab();
	}
  
  	//获得总页数
  	function totalPages(){
  		//如果刚好除尽
  		if(data.length % pageSize == 0){
  			totalPage = data.length / pageSize;
  		}
  		else{
  			totalPage = parseInt(data.length / pageSize) + 1;
  		}
  	}

  	//上一页
  	function leftPages(){
  		if(currentPage != 1){
  			currentPage--;
  			//开始创建
  			creatTab();
  		}
  	}
  	//下一页
  	function rightPages(){
  		if(currentPage != totalPage){
  			currentPage++;
  			//开始创建
  			creatTab();
  		}
  	}
  	//到第几页去
  	function goPage(){
  		currentPage = document.getElementById('goPage').value;
  		//如果输入的页数超出总页数，则到最后一页去！
  		if(currentPage > totalPage){
  			currentPage = totalPage;
  		}
  		if(currentPage < 1){
  			currentPage = 1;
  		}
  		creatTab();
  	}

  	function creatTab(){
  		//清空数据
  		$("#detail tbody").empty();
  		$("#checkalltwo").attr("checked",false);
  		//总页数
  		totalPages();
  		$('#totalNum').text(totalPage);
  		//插入页数
  		$('#goPage').val(currentPage);
  		var str = '';
		$("#detail tbody").empty();
		currentRows  = (totalPage == 1 || currentPage == totalPage) ? data.length : currentPage * pageSize ;
		console.log(currentPage);
		console.log(currentRows);
       	for(var i = (currentPage-1) * pageSize; i < currentRows ;i++){
            if(data[i].zsPackageImformation!=null){
                str += "<tr class='packMx' data='"+data[i].zsPackageImformation.packageId+"' ><td>"+data[i].miejunWupinbaoTiaoma+"</td><td>"+data[i].zsPackageImformation.packageName+"</td><td>"+(data[i].miejunHege==3?"合格":"未审核")+"</td></tr>";
            }else{
                str += "<tr class='packMx' ><td>"+data[i].miejunWupinbaoTiaoma+"</td><td>"+data[i].miejunZhunbeiLiushui+"</td><td>"+(data[i].miejunHege==3?"合格":"未审核")+"</td></tr>";
            }
       	}
        $("#detail tbody").append(str);
  	}
</script>

  
</body>
</html>